﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.Models;
using PBOffice.BLL;

public partial class NewsManager_LookNews : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            List<NewsType> type = new NewsTypeManager().GetAllType();
            ddlNewsType.DataSource = type;
            ddlNewsType.DataBind();
            ddlNewsType.DataTextField = "TypeName";
            ddlNewsType.DataValueField = "TypeId";
            ListItem item = new ListItem("请选择");
            ddlNewsType.Items.Insert(0, item);
            this.AspNetPager1.PageSize = 1;
            this.AspNetPager1.RecordCount = new NewsManager().GetCountByTitleAndType("", "");
            this.DataList1.DataSource = new NewsManager().GetAllNewsByType("", "", this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize);
            this.DataList1.DataBind();
        }
    }
    protected void btnCheck_Click(object sender, EventArgs e)
    {
        string title = this.txtTitle.Text.Trim();
        string type = this.ddlNewsType.Text.Trim();
        if (title.Length == 0)
        {
            title = "";
        }
        if (type == "请选择")
        {
            type = "";
        }
        this.AspNetPager1.RecordCount = new NewsManager().GetCountByTitleAndType(title, type);
        this.DataList1.DataSource = new NewsManager().GetAllNewsByType(title, type, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize);
        this.DataList1.DataBind();
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string title = this.txtTitle.Text.Trim();
        string type = this.ddlNewsType.Text.Trim();
        if (title.Length == 0)
        {
            title = "";
        }
        if (type == "请选择")
        {
            type = "";
        }
        this.AspNetPager1.RecordCount = new NewsManager().GetCountByTitleAndType(title, type);
        this.DataList1.DataSource = new NewsManager().GetAllNewsByType(title, type, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize);
        this.DataList1.DataBind();
    }
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "content")
        {
            DataListItem daItem = (DataListItem)((LinkButton)(e.CommandSource)).Parent;
            int newsId = Convert.ToInt32(DataList1.DataKeys[daItem.ItemIndex]);
            Response.Redirect(string.Format("NewsInfo.aspx?id={0}", newsId));
        }
    }
}